# -*- coding: utf-8 -*-

# @Project : UI_DDTFrameWork
# @Author  : Mr.Deng
# @Time    : 2021/9/22 0:43

from common.seleniumLibrary import PySelenium
from common.tools.assertion import Assertion
from common.tools.getTestData import get_data
from common.tools.decorator import skip_case

from page.baiduSearchPage import BaiDuSearchPage

import unittest
import ddt


@ddt.ddt
class BaiDuSearch(unittest.TestCase):
    """
    百度搜索功能测试用例
    """

    @classmethod
    def setUpClass(cls):
        """实例化类文件"""
        cls.driver = PySelenium()
        cls.baiduSearchPage = BaiDuSearchPage(cls.driver)
        cls.assertion = Assertion(cls.driver)

    @ddt.data(*get_data(fileName="searchData.yaml"))
    @skip_case
    def test_baidu_search(self, testData):
        """
        百度搜索测试
        :param testData: 测试数据
        :return:
        """
        self.driver.Log.info(f"测试用例名称：{testData['caseName']}")
        self.baiduSearchPage.open_search_url()
        self.baiduSearchPage.input_search_value(testData["testData"])
        self.baiduSearchPage.click_search_button()
        pageTitle = self.baiduSearchPage.get_search_title()
        # 判断是否搜索成功
        self.assertion.assert_in(testData["expectation"], pageTitle)

    @classmethod
    def tearDownClass(cls) -> None:
        cls.driver.quit()


if __name__ == '__main__':
    suit = unittest.TestLoader().loadTestsFromTestCase(BaiDuSearch)
    unittest.TextTestRunner().run(suit)
